package com.mall.dao;

import com.mall.domain.ItemCat;
import com.mall.domain.Menus;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 商品类别的持久层接口
 * @author : Bei-Zhen
 * @date : 2021-01-04 16:48
 */
@Repository
public interface IItemCatDao {

    /**
     * 查询商品类别父节点
     * @return
     */
    @Results(id = "itemCatMap",
            value = {
                    @Result(id = true,property = "cat_id",column = "cat_id"),
                    @Result(column = "cat_id",
                            property = "children",
                            many = @Many(select = "com.mall.dao.IItemCatDao.listChild",fetchType = FetchType.LAZY)
                    )
            })
    @Select("select * from tb_item_cat where cat_pid=0 and cat_deleted=0")
    List<ItemCat> getTree();

    /**
     * 查询商品类别子节点
     * @param cat_pid
     * @return
     */
    @ResultMap("itemCatMap")
    @Select("select * from tb_item_cat where cat_pid=#{cat_pid} and cat_deleted=0")
    List<Menus> listChild(@Param("cat_pid")int cat_pid);
}
